home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1139 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.6 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: 'const' binding to specifier in declaration list
  5. Followup-To: comp.std.c++
  6. Date: 17 Apr 1996 10:41:47 PDT
  7. Organization: GABI Software, Sarl.
  8. Approved: austern@isolde.mti.sgi.com
  9. Message-ID: <KANZE.96Apr17121453@slsvgqt.lts.sel.alcatel.de>
  10. References: <3173B383.41C67EA6@rstcorp.com>
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: 17 Apr 1996 10:14:53 GMT
  13. In-Reply-To: "Aaron S. Binns"'s message of 16 Apr 1996 13:17:21 PDT
  14. Apparently-To: std-c++@ncar.UCAR.EDU
  15. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  16.     iQBVAwUBMXUtXEy4NqrwXLNJAQFrCwIAvyqTcA0n2cEcmFev2sa1jpGXlo/WAxoW
  17.     COfFSMosvCSIBZGcaAQGSiygbFipEh4HWDBTspYdhSI6eHN7BxM8Zw==
  18.     =eI/Y
  19. Originator: austern@isolde.mti.sgi.com
  20.  
  21. In article <3173B383.41C67EA6@rstcorp.com> "Aaron S. Binns"
  22. <asbinn@rstcorp.com> writes:
  23.  
  24. |> [Moderator's note: This is crossposted to comp.std.c++ and
  25. |> comp.lang.c++, and followups have been set to comp.std.c++. mha]
  26.  
  27. |> I recently came across a piece of code that reads:
  28.  
  29. |> class A {
  30. |>   // contents of class A
  31. |> } a1, *a2, const *a3;
  32.  
  33. While I personally wouldn't write anything like this, it is definitly
  34. legal.
  35.  
  36. |> This looks pretty bogus to me.  I thought that the 'const' applied
  37. |> to the elaborated specifier 'class A'.  If the 'const' qualifier is
  38. |> supposed to apply to the pointer in 'a3', then it should come _after_
  39. |> the '*'.
  40.  
  41. No, it is the A being pointed to that is const, not the pointer.
  42.  
  43. Separating each of the definitions out into a separate statement makes
  44. this obvious:
  45.  
  46.     class A { ... } ;
  47.     A               a1 ;
  48.     A*              a2 ;
  49.     A const*        a3 ;
  50.  
  51. |> I think that either one of the two following was intended.
  52.  
  53. |> 1)
  54.  
  55. |> class A {
  56. |>   // contents of class A
  57. |> } a1, *a2, * const a3;
  58.  
  59.  
  60. |> 2)
  61.  
  62. |> class A {
  63. |>   // contents of class A
  64. |> } a1, *a2;
  65.  
  66. |> A const *a3;  // Or const A *a3;
  67.  
  68. Regardless of what was intended, 2 is the interpretation required by
  69. the draft standard (and by the C standard).
  70. -- 
  71. James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
  72. GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
  73. Conseils, itudes et rialisations en logiciel orienti objet --
  74.                 -- A la recherche d'une activiti dans une region francophone
  75. ---
  76. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  77.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  78.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  79.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  80.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  81. ]
  82.